using Newtonsoft.Json;
using Simple.Contracts.Enums.Common;
using Simple.Contracts.Models.Common.File;
using Simple.Contracts.Models.Common.Page;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Simple.Contracts.Models
{
    /// <summary>
    /// 获取老人列表
    /// </summary>
    public class ElderlyInfoListInput : PageInput
    {
        /// <summary>
        /// 老人姓名
        /// </summary>
        public string? name { get; set; }

        /// <summary>
        /// 老人称谓
        /// </summary>
        public string? nickName { get; set; }

        /// <summary>
        /// 身份证号
        /// </summary>
        public string? idCard { get; set; }

        /// <summary>
        /// 房间号
        /// </summary>
        public string? roomNumber { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public int? status { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public int? gender {  get; set; }

        /// <summary>
        /// 血型
        /// </summary>
        public int? bloodType {  get; set; }

        /// <summary>
        /// 行动能力状态
        /// </summary>
        public int? mobilityStatus { get; set; }

        /// <summary>
        /// 是否设置过照护计划：0=未设置，1=已设置
        /// </summary>
        public int? IsSettingCarePlan { get; set; }
    }

    /// <summary>
    /// 老人信息
    /// </summary>
    public class ElderlyInfoDto
    {
        /// <summary>
        /// 老人唯一ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 老人姓名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 老人昵称
        /// </summary>
        public string? NickName {  get; set; }

        /// <summary>
        /// 性别：0-未知，1-男，2-女
        /// </summary>
        public int? Gender { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public string? GenderText
        {
            get
            {
                if (Gender.HasValue)
                {
                    if (Enum.IsDefined(typeof(GenderEnum), Gender.Value))
                    {
                        GenderEnum enumValue = (GenderEnum)Gender.Value;
                        return enumValue.ToString();
                    }
                }
                return null;
            }
        }

        /// <summary>
        /// 身份证号
        /// </summary>
        public string IdCard { get; set; }

        /// <summary>
        /// 出生日期
        /// </summary>
        public string? DateOfBirth { get; set; }

        /// <summary>
        /// 年龄
        /// </summary>
        public int? Age {  get; set; }

        /// <summary>
        /// 房间号
        /// </summary>
        public string? RoomNumber { get; set; }

        /// <summary>
        /// 床位号
        /// </summary>
        public string? BedNumber { get; set; }

        /// <summary>
        /// 本人联系电话
        /// </summary>
        public string? ContactPhone { get; set; }

        /// <summary>
        /// 微信号
        /// </summary>
        public string WechatId {  get; set; }

        /// <summary>
        /// 紧急联系人姓名
        /// </summary>
        public string EmergencyContactName { get; set; }

        /// <summary>
        /// 紧急联系人关系
        /// </summary>
        public string? EmergencyContactRelation { get; set; }

        /// <summary>
        /// 紧急联系人电话
        /// </summary>
        public string EmergencyContactPhone { get; set; }

        /// <summary>
        /// 过敏史
        /// </summary>
        public string? Allergies {  get; set; }

        /// <summary>
        /// 血型
        /// </summary>
        public int? BloodType { get; set; }

        /// <summary>
        /// 既往史
        /// </summary>
        public string? MajorMedicalHistory {  get; set; }

        /// <summary>
        /// 当前服用药物
        /// </summary>
        public string? CurrentMedications {  get; set; }

        /// <summary>
        /// 行动能力状态
        /// </summary>
        public int MobilityStatus { get; set; }

        /// <summary>
        /// 风险防范
        /// </summary>
        public string RiskPrevention { get; set; }

        /// <summary>
        /// 特殊照护注意事项
        /// </summary>
        public string SpecialCarePrecautions { get; set; }

        /// <summary>
        /// 个性化照护需求
        /// </summary>
        public string PersonalizedCareNeeds { get; set; }

        /// <summary>
        /// 是否设置过照护计划：0=未设置，1=已设置
        /// </summary>
        public int? IsSettingCarePlan { get; set; }

        /// <summary>
        ///  饮食要求
        /// </summary>
        public string? DietaryRequirements {  get; set; }

        /// <summary>
        /// 入住日期
        /// </summary>
        public string? CheckInDate { get; set; }

        /// <summary>
        /// 当前状态
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string AvatarUrl {  get; set; }

        /// <summary>
        /// 照片存储路径
        /// </summary>
        public List<ImageModel>? PhotoUrls { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public string CreateTime { get; set; }

        /// <summary>
        /// 合同到期日期
        /// </summary>
        public string? ContractExpiryDate {  get; set; }

        /// <summary>
        /// 个人生活习惯
        /// </summary>
        public string? PersonalHabits {  get; set; }

        /// <summary>
        /// 其他备注
        /// </summary>
        public string? Notes { get; set; }

        /// <summary>
        /// 家庭地址
        /// </summary>
        public string? Address { get; set; }

        /// <summary>
        /// 属相
        /// </summary>
        public string? ChineseZodiac {  get; set; }

        /// <summary>
        /// 照护人员
        /// </summary>
        public List<ElderlyCareWorkerDto> ElderlyCareWorkerList {  get; set; }

        /// <summary>
        /// 照护人员
        /// </summary>
        public List<string>? CareWorkerEmployeeIds
        {
            get
            {
                return ElderlyCareWorkerList.Select(x => x.EmployeeId.ToString()).ToList();
            }
        }
    }

    /// <summary>
    /// 照护人员
    /// </summary>
    public class ElderlyCareWorkerDto
    {
        /// <summary>
        /// 照护员工Id
        /// </summary>
        public long EmployeeId { get; set; }

        /// <summary>
        /// 照护员名称
        /// </summary>
        public string EmployeeName {  get; set; }
    }

    /// <summary>
    /// 保存老人信息
    /// </summary>
    public class ElderlyInfoSaveInput
    {
        /// <summary>
        /// 老人唯一ID
        /// </summary>
        public long? Id { get; set; }

        /// <summary>
        /// 老人姓名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 老人昵称
        /// </summary>
        public string? NickName { get; set; }

        /// <summary>
        /// 性别
        /// </summary>
        public int? Gender { get; set; }

        /// <summary>
        /// 身份证号
        /// </summary>
        public string? IdCard { get; set; }

        /// <summary>
        /// 出生日期
        /// </summary>
        public DateTime? DateOfBirth { get; set; }

        /// <summary>
        /// 属相
        /// </summary>
        public string? ChineseZodiac { get; set; }

        /// <summary>
        /// 房间号
        /// </summary>
        public string? RoomNumber { get; set; }

        /// <summary>
        /// 床位号
        /// </summary>
        public string? BedNumber { get; set; }

        /// <summary>
        /// 本人联系电话
        /// </summary>
        public string? ContactPhone { get; set; }

        /// <summary>
        /// 微信号
        /// </summary>
        public string? WechatId { get; set; }

        /// <summary>
        /// 紧急联系人姓名
        /// </summary>
        public string? EmergencyContactName { get; set; }

        /// <summary>
        /// 紧急联系人电话
        /// </summary>
        public string? EmergencyContactPhone { get; set; }

        /// <summary>
        /// 紧急联系人关系
        /// </summary>
        public string? EmergencyContactRelation { get; set; }

        /// <summary>
        /// 血型
        /// </summary>
        public int? BloodType { get; set; }

        /// <summary>
        /// 过敏史
        /// </summary>
        public string? Allergies { get; set; }

        /// <summary>
        /// 重大疾病史
        /// </summary>
        public string? MajorMedicalHistory { get; set; }

        /// <summary>
        /// 当前服用药物
        /// </summary>
        public string? CurrentMedications { get; set; }

        /// <summary>
        /// 行动能力状态
        /// </summary>
        public int MobilityStatus { get; set; }

        /// <summary>
        /// 饮食要求
        /// </summary>
        public string? DietaryRequirements { get; set; }

        /// <summary>
        /// 入住日期
        /// </summary>
        public DateTime? CheckInDate { get; set; }

        /// <summary>
        /// 合同到期日期
        /// </summary>
        public DateTime? ContractExpiryDate { get; set; }

        /// <summary>
        /// 照片存储路径
        /// </summary>
        public List<ImageModel>? PhotoUrls { get; set; }

        /// <summary>
        /// 个人生活习惯
        /// </summary>
        public string? PersonalHabits { get; set; }

        /// <summary>
        /// 其他备注
        /// </summary>
        public string? Notes { get; set; }

        /// <summary>
        /// 地址
        /// </summary>
        public string? Address { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string? AvatarUrl { get; set; }

        /// <summary>
        /// 当前状态：1=在住、2=退住
        /// </summary>
        public int Status { get; set; } = 0;

        /// <summary>
        /// 照护人员
        /// </summary>
        public List<ElderlyCareWorkerDto> ElderlyCareWorkerList { get; set; }
    }

    /// <summary>
    /// 删除老人信息
    /// </summary>
    public class ElderlyInfoDeleteInput
    {
        /// <summary>
        /// 老人id列表
        /// </summary>
        public List<long> id { get; set; }
    }

    /// <summary>
    /// 设置老人状态
    /// </summary>
    public class ElderlyInfoSetStatusInput
    {
        /// <summary>
        /// 老人Id
        /// </summary>
        public long id { get; set; }

        /// <summary>
        /// 状态：1=在住、2=退住、3=请假、4=住院
        /// </summary>
        public int Status { get; set; }
    }

    /// <summary>
    /// 保存老人照护计划内容
    /// </summary>
    public class SaveElderlyCarePlanInput
    {
        /// <summary>
        /// 老人唯一ID
        /// </summary>
        public long ElderlyId { get; set; }

        /// <summary>
        /// 既往史
        /// </summary>
        public string? MajorMedicalHistory { get; set; }

        /// <summary>
        /// 过敏史
        /// </summary>
        public string? Allergies { get; set; }

        /// <summary>
        /// 风险防范
        /// </summary>
        public string? RiskPrevention { get; set; }

        /// <summary>
        /// 特殊照护注意事项
        /// </summary>
        public string? SpecialCarePrecautions { get; set; }

        /// <summary>
        /// 个性化照护需求
        /// </summary>
        public string? PersonalizedCareNeeds { get; set; }

        /// <summary>
        /// 照护计划动作
        /// </summary>
        public List<ElderlyCarePlanMissionDto>? PlanMissionList {  get; set; }
    }

    /// <summary>
    /// 老人照护计划动作
    /// </summary>
    public class ElderlyCarePlanMissionDto
    {
        /// <summary>
        /// 主键Id
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 照护项目分类Id
        /// </summary>
        public long CategorizeId { get; set; }

        /// <summary>
        /// 照护项目Id
        /// </summary>
        public long CareMissionId { get; set; }

        /// <summary>
        /// 照护项目名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 照护项目描述、注意事项
        /// </summary>
        public string? Description { get; set; }

        /// <summary>
        /// 是否每日照护任务：0=否、1=是
        /// </summary>
        public int IsDailyMission { get; set; } = 1;

        /// <summary>
        /// 每日照护任务：建议开始时间（HH:mm）
        /// </summary>
        public string? DailyMissionStartTime { get; set; }

        /// <summary>
        /// 每日照护任务：建议开始时间（HHmm）
        /// </summary>
        public int? DailyMissionStartTimeValue { get; set; }

        /// <summary>
        /// 每日照护任务：建议结束时间（HH:mm）
        /// </summary>
        public string? DailyMissionEndTime { get; set; }

        /// <summary>
        /// 每日照护任务：建议结束时间（HHmm）
        /// </summary>
        public int? DailyMissionEndTimeValue { get; set; }

        /// <summary>
        /// 每日照护任务：建议执行次数
        /// </summary>
        public int? DailyMissionExecutionCount { get; set; }

        /// <summary>
        /// 是否需要拍照打卡
        /// </summary>
        public bool? IsTakePhotos { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int? Sort { get; set; }

        /// <summary>
        /// 是否删除：0=未删除、1=已删除
        /// </summary>
        public int IsDelete { get; set; }

        /// <summary>
        /// 照护项目执行护理员工列表
        /// </summary>
        public string? CareWorkerEmployeeIds { get; set; }

        /// <summary>
        /// 照护项目执行护理员工列表
        /// </summary>
        public List<string> CareWorkerEmployeeIdList
        {
            get
            {
                if (string.IsNullOrEmpty(CareWorkerEmployeeIds))
                {
                    return new List<string>();
                }
                else
                {
                    return CareWorkerEmployeeIds.Split(',').ToList();
                }
            }
        }
    }

    /// <summary>
    /// 老人照护项目
    /// </summary>
    public class ElderlyCarePlanMissionInfoDto : ElderlyCarePlanMissionDto
    {
        /// <summary>
        /// 是否完成
        /// </summary>
        public bool IsComplete {  get; set; }

        /// <summary>
        /// 执行次数
        /// </summary>
        public int ExecutionCount {  get; set; }
    }

    /// <summary>
    /// 老人照护信息
    /// </summary>
    public class ElderlyCareInfoDto : ElderlyInfoDto
    {
        /// <summary>
        /// 照护项目列表
        /// </summary>
        public List<ElderlyCarePlanMissionInfoDto> CarePlanMissionList {  get; set; }

        /// <summary>
        /// 完成照护项目数量
        /// </summary>
        public long CompleteMissionCount {  get; set; }
    }

    /// <summary>
    /// 保存老人照护记录
    /// </summary>
    public class SaveElderlyCareRecordInput
    {
        /// <summary>
        /// 老人照护项目Id
        /// </summary>
        public long careMissionId { get; set; }

        /// <summary>
        /// 照护记录内容
        /// </summary>
        public string? recordContent {  get; set; }

        /// <summary>
        /// 有效的音频列表
        /// </summary>
        public List<RecordMp3FileInput>? recordMp3FileList {  get; set; }

        /// <summary>
        /// 删除的音频列表
        /// </summary>
        public List<RecordMp3FileInput>? recordMp3DeleteFileList {  get; set; }

        /// <summary>
        /// 有效图片列表
        /// </summary>
        public List<RecordImageFileInput>? recordImageFileList {  get; set; }

        /// <summary>
        /// 删除的图片列表
        /// </summary>
        public List<RecordImageFileInput>? recordImageDeleteFileList { get; set; }
    }
    /// <summary>
    /// 音频列表
    /// </summary>
    public class RecordMp3FileInput
    {
        public double durationSecond {  get; set; }
        public long fileId {  get; set; }
        public string fileUrl {  get; set; }
        public string? mp3Text {  get; set; }
    }
    /// <summary>
    /// 图片列表
    /// </summary>
    public class RecordImageFileInput
    {
        public long fileId { get; set; }
        public string fileUrl { get; set; }
    }

    /// <summary>
    /// 获取照护记录列表
    /// </summary>
    public class GetElderlyCareRecordListInput : PageInput
    {
        /// <summary>
        /// 老人
        /// </summary>
        public long? ElderlyId { get; set; }
    }

    /// <summary>
    /// 照护记录
    /// </summary>
    public class ElderlyCareRecordDto
    {
        /// <summary>
		/// 主键Id
		/// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 长者Id
        /// </summary>
        public long ElderlyId { get; set; }

        /// <summary>
        /// 照护项目分类Id
        /// </summary>
        public long CategorizeId { get; set; }

        /// <summary>
        /// 照护项目Id
        /// </summary>
        public long CareMissionId { get; set; }

        /// <summary>
        /// 照护项目名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 照护项目描述、注意事项
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 是否每日照护任务：0=否、1=是
        /// </summary>
        public int IsDailyMission { get; set; } = 1;

        /// <summary>
        /// 每日照护任务：建议开始时间（HH:mm）
        /// </summary>
        public string DailyMissionStartTime { get; set; }

        /// <summary>
        /// 每日照护任务：建议结束时间（HH:mm）
        /// </summary>
        public string DailyMissionEndTime { get; set; }

        /// <summary>
        /// 每日照护任务：建议结束时间（HHmm）
        /// </summary>
        public int? DailyMissionEndTimeValue { get; set; }

        /// <summary>
        /// 每日照护任务：建议开始时间（HHmm）
        /// </summary>
        public int? DailyMissionStartTimeValue { get; set; }

        /// <summary>
        /// 每日照护任务：建议执行次数
        /// </summary>
        public int? DailyMissionExecutionCount { get; set; }

        /// <summary>
        /// 是否需要拍照打卡：0=不需要、1=需要
        /// </summary>
        public int? IsTakePhotos { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public long CreateBy { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        public long UpdateBy { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public int? Sort { get; set; }

        /// <summary>
        /// 照护项目执行护理员工列表
        /// </summary>
        public string CareWorkerEmployeeIds { get; set; }

        /// <summary>
        /// 照护项目执行护理员工名称列表
        /// </summary>
        public List<string> CareWorkerEmployeeNames {  get; set; }

        /// <summary>
        /// 是否删除：0=未删除、1=已删除
        /// </summary>
        public int IsDelete { get; set; }

        /// <summary>
        /// 长者照护计划项目Id
        /// </summary>
        public long ElderlyCareMissionId { get; set; }

        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime CompletionTime { get; set; }

        /// <summary>
        /// 是否在建议时间内完成：0=不是、1=是
        /// </summary>
        public int CompletionAtSpecifiedTime { get; set; }

        /// <summary>
        /// 完成人
        /// </summary>
        public long CompletionBy { get; set; }

        /// <summary>
        /// 完成人名称
        /// </summary>
        public string CompletionByName {  get; set; }

        /// <summary>
        /// 记录内容
        /// </summary>
        public string RecordContent { get; set; }

        /// <summary>
        /// 照护记录媒体内容
        /// </summary>
        public List<ElderlyCareRecordMediaDto> ElderlyCareRecordMediaList {  get; set; }
    }

    public class ElderlyCareRecordMediaDto
    {
        /// <summary>
		/// 主键Id
		/// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 公司Id
        /// </summary>
        public long CompanyId { get; set; }

        /// <summary>
        /// 长者照护记录Id
        /// </summary>
        public long ElderlyCareRecordId { get; set; }

        /// <summary>
        /// 文件Id
        /// </summary>
        public long FileId { get; set; }

        /// <summary>
        /// 文档地址
        /// </summary>
        public string FileUrl { get; set; }

        /// <summary>
        /// 文件类型：mp3、image、video
        /// </summary>
        public string FileType { get; set; }

        /// <summary>
        /// 音频长度（单位秒）
        /// </summary>
        public double? Mp3Second { get; set; }

        /// <summary>
        /// 音频文字（语音识别内容）
        /// </summary>
        public string Mp3Text { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        public long CreateBy { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; }

        /// <summary>
        /// 更新人
        /// </summary>
        public long UpdateBy { get; set; }

        /// <summary>
        /// 是否删除：0=未删除、1=已删除
        /// </summary>
        public int IsDelete { get; set; }
    }
}